﻿using System;
using System.Diagnostics;
using System.Data.Common;
using System.Collections.Generic;
using System.Threading;
using NUnit;
using NUnit.Framework;
using Rhino.Mocks;

namespace mForum.Infrastructure.NHibernate.Tests.Repository
{
    using mForum.Domain.DomainObject;
    using mForum.Core.Infrastructure;
    using mForum.Domain.Repository;
    using mForum.Infrastructure.NHibernate;
    using mForum.Infrastructure.NHibernate.Repository;
    using mForum.Infrastructure.NHibernate.Tests;

    public class UserRepositoryTest : BaseDatabaseTest
    {
        [Test]
        public void can_get_user_by_id()
        {
            Guid id = new Guid("5da28936-312a-4dcd-8ba8-30d1b2a1e770");
            User result = _userRepository.GetById(id);

            Assert.AreEqual(result.Id, id);
        }

        [Test]
        public void can_find_user_by_username()
        {
            string username = "mForum";

            User result = _userRepository.FindUserByUsername(username);

            Assert.IsNotNull(result);

            Assert.AreEqual(result.Username, username);
        }

        [Test]
        public void can_find_user_by_email()
        {
            string email = "test@ble.pl";

            User result = _userRepository.FindUserByEmail(email);

            Assert.IsNotNull(result);

            Assert.AreEqual(result.Email, email);
        }

        [Test]
        public void can_count_all_users()
        {
            int result = -1;
            int expectedResult = 2;

            result = _userRepository.CountAllUsers();

            Assert.IsNotNull(result);
            Assert.GreaterOrEqual(expectedResult, result);
        }

        [Test]
        public void can_count_all_users_online()
        {
            int numberOfOnlineUsers = 0;
            int result = -1;

            result = _userRepository.CountNumberOfOnlineUsers();

            Assert.IsNotNull(result);
            Assert.AreEqual(numberOfOnlineUsers, result);
        }

        [Test]
        public void can_modify_user()
        {
            string username = "test";

            User testUser = _userRepository.FindUserByUsername(username);

            testUser.Email = "test@asas.pl";

            _uow.Commit();
        }
    }
}
